package com.bookhouse.service.impl;

import java.util.HashSet;
import java.util.Set;

import com.bookhouse.dao.CategoryDao;
import com.bookhouse.domain.Category;
import com.bookhouse.service.CategoryService;

public class CategoryServiceImpl implements CategoryService {

	private CategoryDao categoryDao;

	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

	@Override
	public Set<Category> getAllCategory() {
		Set<Category> sets = new HashSet<Category>();
		Category categories = categoryDao.get(Category.class, 0);
		Set<Category> levels1 = categories.getChildrenCategory();
		for (Category level1 : levels1) {
			sets.add(level1);
			level1.setSet(new HashSet<Category>());
			Set<Category> levels2 = level1.getChildrenCategory();
			for (Category level2 : levels2) {
				level1.getSet().add(level2);
				level2.setSet(new HashSet<Category>());
				Set<Category> levels3 = level2.getChildrenCategory();
				for (Category level3 : levels3) {
					level2.getSet().add(level3);
				}
			}
		}
		return sets;
	}
}
